package com.info33.platform.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.info33.platform.common.mvc.controller.BaseController;
import com.info33.platform.common.mvc.vo.Result;
import com.info33.platform.system.dto.SysAppTenantMenuDTO;
import com.info33.platform.system.entity.SysAppMenu;
import com.info33.platform.system.entity.SysAppTenantMenu;
import com.info33.platform.system.service.SysAppTenantMenuService;
import com.info33.platform.system.vo.SysAppHomeVO;
import com.info33.platform.system.vo.SysAppTenantMenuVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author admin
 */
@RestController
@RequestMapping("/SysAppTenantMenu")
@Api(tags = "系统 - 管理端 app - 租户 - 菜单")
public class SysAppTenantMenuController extends BaseController<SysAppTenantMenuService, SysAppTenantMenu> {

    private final SysAppTenantMenuService sysAppTenantMenuService;

    @Autowired
    public SysAppTenantMenuController(SysAppTenantMenuService sysAppTenantMenuService) {
        super(sysAppTenantMenuService);
        this.sysAppTenantMenuService = sysAppTenantMenuService;
    }

    /*
     * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     *
     * app
     *
     * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     */

    @GetMapping(value = "/app/home")
    @ApiOperation(value = "app - 首页")
    public Result<SysAppHomeVO> appHome() {
        return Result.ok(sysAppTenantMenuService.appHome(getCurrentUser()));
    }

    @GetMapping(value = "/app/more")
    @ApiOperation(value = "app - 首页 - 菜单 - 更多")
    public Result<SysAppTenantMenuVO> appMore() {
        return Result.ok(sysAppTenantMenuService.appMore(getCurrentUser()));
    }

    @GetMapping(value = "/app/home/menu")
    @ApiOperation(value = "app - 首页内容菜单")
    public Result<List<SysAppMenu>> appHomeMenu() {
        return Result.ok(sysAppTenantMenuService.appHomeMenu(getCurrentUser()));
    }

    @GetMapping(value = "/app/my/menu")
    @ApiOperation(value = "app - 我所拥有的菜单")
    public Result<List<SysAppMenu>> appMyMenu() {
        return Result.ok(sysAppTenantMenuService.appHomeMenuToSort(getCurrentUser()));
    }

    /*
     * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     *
     * pc
     *
     * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     */

    @PostMapping(value = "/page/{pageNum}/{pageSize}")
    @ApiOperation(value = "pc - 菜单分页", notes = "入参说明：<br/>" +
            "menuDTO.pid = 1：顶级菜单<br/>" +
            "menuDTO.pid = ?：二级菜单（menuId 取值）")
    public Result<IPage<SysAppTenantMenuVO>> pcPage(
            @RequestBody SysAppTenantMenuDTO dto,
            @PathVariable int pageNum,
            @PathVariable int pageSize) {
        return Result.ok(sysAppTenantMenuService.pcPage(new Page<>(pageNum, pageSize), dto, getCurrentUser()));
    }

    @GetMapping(value = "/detail/{id}")
    @ApiOperation(value = "pc - 菜单详情", notes = "权限详情")
    public Result<SysAppTenantMenuVO> pcDetail(
            @PathVariable(value = "id") Long id) {
        return Result.ok(sysAppTenantMenuService.pcDetail(id));
    }

    @PatchMapping(value = "/reset/{id}")
    @ApiOperation(value = "pc - 重置")
    public Result<Object> pcReset(
            @PathVariable(value = "id") Long id) {
        return sysAppTenantMenuService.pcReset(id);
    }

    @PutMapping(value = "/edit")
    @ApiOperation(value = "pc - 编辑")
    public Result<Object> pcEdit(
            @RequestBody SysAppTenantMenuDTO dto) {
        return sysAppTenantMenuService.pcEdit(dto);
    }

    @GetMapping(value = "/tree")
    @ApiOperation(value = "pc - 树结构")
    public Result<List<SysAppTenantMenuVO>> pcTree() {
        return Result.ok(sysAppTenantMenuService.pcTree(getTenantId()));
    }
}